var barDisplay : float = 0;
var pos : Vector2 = new Vector2(20,20);
var size : Vector2 = new Vector2(100,30);
var progressBarEmpty : Texture2D;
var progressBarFull : Texture2D;

function OnGUI()
{
  var oldMatrix : Matrix4x4;
  var tMatrix : Matrix4x4;
  var width : int = 1016; //Reference resolution
  var height : int = 496; //Reference resolution

  oldMatrix = GUI.matrix; //Store current matrix
  tMatrix = Matrix4x4.TRS(Vector3.zero, Quaternion.identity, Vector3(1.0*Screen.width/width, 1.0*Screen.height/height, 1.0)); //Construct matrix to scale to actual view size
  GUI.matrix = tMatrix; //Set the GUI matrix to the scaling matrix
  // draw the background:
  GUI.BeginGroup (new Rect (pos.x, pos.y, size.x, size.y));
      GUI.Box (Rect (0,0, size.x, size.y),progressBarEmpty);

      // draw the filled-in part:
      GUI.BeginGroup (new Rect (0, 0, size.x * barDisplay, size.y));
          GUI.Box (Rect (0,0, size.x, size.y),progressBarFull);
      GUI.EndGroup ();

  GUI.EndGroup ();

  GUI.matrix = oldMatrix; //Set the original matrix back
} 

function updateHealth(healthLeft : float, health : float){
  barDisplay = healthLeft/health;
}

function setHealth(health : float){
  barDisplay = health;
}